﻿using BootstrapBlazorApp.Shared.Data.SYS;

namespace BootstrapBlazorApp.Shared.Shared;

public interface ITokenContext
{
    /// <summary>
    /// 获得 是否已授权
    /// </summary>
    bool IsAuthenticated { get; }

    CurrentUser CurrentUser { get; }

    /// <summary>
    /// 重载应用
    /// </summary>
    void ReloadApp();

    /// <summary>
    /// 检查当前请求 许可 是否已授权
    /// </summary>
    /// <param name="permission">许可</param>
    /// <returns></returns>
    bool Permission(string permission);

    /// <summary>
    /// 是否存在会话键
    /// </summary>
    /// <param name="key"></param>
    bool HasSession(string key);

    /// <summary>
    /// 获取会话值
    /// </summary>
    /// <param name="key"></param>
    TValue? GetSession<TValue>(string key);

    /// <summary>
    /// 更新会话值
    /// </summary>
    /// <typeparam name="TValue"></typeparam>
    /// <param name="key">键</param>
    /// <param name="value">值</param>
    bool SetSession<TValue>(string key, TValue? value);

    /// <summary>
    /// 移出会话值
    /// </summary>
    /// <param name="key"></param>
    bool RemoveSession(string key);

    /// <summary>
    /// 清空会话，重新登录
    /// </summary>
    void ClearSession();
}
